package com.thf.service.impl;

import com.thf.dao.EchartsOneDao;
import com.thf.model.EchartsOneModel;
import com.thf.model.ResultData;
import com.thf.service.EchartsOneService;
import com.thf.util.ResultTool;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class EchartsOneServiceImpl implements EchartsOneService {

    @Resource
    private EchartsOneDao echartsOneDao;
    @Override
    public ResultData<Map<String, Object>> findAll() {
        List<EchartsOneModel> allData = echartsOneDao.findAll();
        if(allData==null|| allData.size()<=0){
            return new ResultData<Map<String,Object>>(ResultTool.CODE_ERROR);
        }
        List<String> typeData = new ArrayList<>();
        List<Map<String,Object>> resultData = new ArrayList<>();
        for (EchartsOneModel model: allData) {
            Map<String,Object> data = new HashMap<>();
            typeData.add(model.getType());
            data.put("name",model.getType());
            data.put("type","line");
            data.put("stack","总量");
            List<Integer> numData = new ArrayList<>();
            numData.add(model.getMonday());
            numData.add(model.getTuesday());
            numData.add(model.getWednesday());
            numData.add(model.getThursday());
            numData.add(model.getFriday());
            numData.add(model.getSaturday());
            numData.add(model.getWeekday());
            data.put("data",numData);
            resultData.add(data);
        }
        Map<String,Object> map = new HashMap<>();
        map.put("typeData",typeData);
        map.put("data",resultData);
        return new ResultData<Map<String,Object>>(ResultTool.CODE_SUCCES,map);
    }

    @Override
    public List<EchartsOneModel> find() {
        return echartsOneDao.findAll();
    }
}
